from pydantic import BaseModel
from typing import Optional, List
import datetime

# 商品模型
class ProductBase(BaseModel):
    name: str
    price: float
    original_price: float
    image: str
    rating: float
    reviews: int
    category: str
    is_new: Optional[bool] = False
    is_hot: Optional[bool] = False
    date_added: datetime.datetime

class ProductCreate(ProductBase):
    pass

class Product(ProductBase):
    id: int
    
    class Config:
        from_attributes = True

# 用户模型
class UserBase(BaseModel):
    name: str
    email: str

class UserCreate(UserBase):
    password: str

class User(UserBase):
    id: int
    created_at: datetime.datetime
    
    class Config:
        from_attributes = True

# 购物车模型
class CartItemBase(BaseModel):
    product_id: int
    quantity: Optional[int] = 1

class CartItemCreate(CartItemBase):
    pass

class CartItem(CartItemBase):
    id: int
    owner_id: int
    
    class Config:
        from_attributes = True

# 登录/认证模型
class Token(BaseModel):
    access_token: str
    token_type: str

class TokenData(BaseModel):
    email: Optional[str] = None